<?php

/* @todo: refactor Settings/SettingsForms */
class TemplateSettings extends Settings {
	// Singleton
    protected static $_instance;
    public static function getInstance(Setting $settingModel=null){
		if (!(self::$_instance instanceof self)){
			self::$_instance = new self($settingModel);
		}
		return self::$_instance;
    }

	public function initSettingModel(){
        if ($this->settingModel==""){
            $this->settingModel=Doctrine::getTable("TemplateSetting")->getCurrent();
            if (empty($this->settingModel)){
                $this->settingModel=new TemplateSetting();
                $settings=Settings::getInstance();
                $templateId=$settings->getValue("template.template_id", 1);
                $this->settingModel->setTemplateId($templateId);
            }
        }
	}

	public function initDefaults(){
        $this->initSettingModel();
        
		$settingForm=new TemplateSettingForm($this->settingModel);
		$this->defaults=$settingForm->getDefaults();
	}

	/**
	 * Shortcut to model
	 */
	public function getDirectoryName(){
		return $this->settingModel->getTemplate()->getDirectoryName();
	}





}
